<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width:500px;
            height:500px;
            border:1px solid black;
        }
    </style>
    <script>
        function doConfirm(){
            var inputs=document.getElementsByName("loveName");//集合
            var box=document.querySelector(".box");//DOM对象
            var count=0;
            var arr=[];
            for(var i=0;i<inputs.length;i++){
                if(inputs[i].checked){//true，说明是被选中的
                    count++;
                    arr.push(inputs[i].value);
                }
            }
            var str=arr.join(",");//将数组变成字符串
            box.innerHTML=str;//将字符串添加到div元素中去
            console.log("您勾选了"+count+"个");
        }
    </script>
</head>
<body>
    <p>请选择你喜欢的名字:</p>
    <div>
        <input type="checkbox" name="loveName"  value="王紫薇">王紫薇
        <input type="checkbox" name="loveName"  value="唐嫣">唐嫣
        <input type="checkbox" name="loveName"  value="杨幂">杨幂
        <input type="checkbox" name="loveName"  value="唐三">唐三
    </div>
    <div class="box">

    </div>
    <input type="button" value="确认按钮" onclick="doConfirm()">
</body>
</html>